<%@ Page Language="C#" MasterPageFile="~/master/admin.master" AutoEventWireup="true"
    CodeFile="product-add.aspx.cs" Inherits="admin_product_add" ValidateRequest="false" %>

<%@ Register Namespace="ECommerce.Library.Web" TagPrefix="ucc" %>
<%@ Register Src="~/controls/wucAdminValidator.ascx" TagName="AdminValidator" TagPrefix="wuc" %>
<%@ Register Src="~/controls/wucEmptyGridMessage.ascx" TagName="EmptyGridMessage"
    TagPrefix="wuc" %>
<asp:Content ID="cntMiddleContent" ContentPlaceHolderID="cphMiddleContent" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div class="admin-function-top inline">
        <ucc:ResponseMessage ID="uccResponseMessage" runat="server"></ucc:ResponseMessage>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
            DisplayMode="BulletList" ShowMessageBox="true" HeaderText="Please correct the following:"
            CssClass="adminValidator" />
        <fieldset>
       <%--     <asp:Button runat="server" ID="btnExportImport" CssClass="btn-regular" Text="Import Products"
                OnClick="btnExportImport_Click" CausesValidation="false" />--%>
            <br />
            <label>
                Name</label>
            <asp:TextBox ID="tbxProductName" runat="server" Width="300px" CssClass="text"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbxProductName"
                ErrorMessage="Product name is required" Display="dynamic" SetFocusOnError="true">
                <wuc:AdminValidator ID="AdminValidator1" runat="server" />
            </asp:RequiredFieldValidator>
            <br />
            <label>
                Alternate Name</label>
            <asp:TextBox ID="tbxProductName2" runat="server" Width="300px" CssClass="text"></asp:TextBox>
            <br />
            <label>
                Category</label>
            <asp:DropDownList ID="ddlParent" runat="server" Width="200px">
            </asp:DropDownList>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ddlParent"
                ErrorMessage="Please select a category" Display="dynamic" SetFocusOnError="true"
                InitialValue="1">
                <wuc:AdminValidator ID="AdminValidator3" runat="server" />
            </asp:RequiredFieldValidator>
           <%-- <br />
            <label>
                Supplier</label>
            <asp:DropDownList ID="ddlBrand" runat="server" Width="200px">
            </asp:DropDownList>--%>
            <br />
            <label>
                Display Order</label>
            <asp:TextBox ID="tbxDisplayOrder" runat="server" CssClass="text" Width="52px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="tbxDisplayOrder"
                ErrorMessage="Please provide display order" Display="dynamic" SetFocusOnError="true">
                <wuc:AdminValidator ID="AdminValidator5" runat="server" />
            </asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="tbxDisplayOrder"
                Display="dynamic" ErrorMessage="<%$ Code:ECommerce.Library.RegExUtil.NumberOnlyFormatError %>"
                ValidationExpression="<%$ Code:ECommerce.Library.RegExUtil.NumberOnlyFormat %>">
                <wuc:AdminValidator ID="AdminValidator8" runat="server" />
            </asp:RegularExpressionValidator>
            <br />
            <label>
                Price $</label>
            <asp:TextBox ID="tbxPrice" runat="server" CssClass="text" Width="52px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="tbxPrice"
                ErrorMessage="Please provide price" Display="dynamic" SetFocusOnError="true">
                <wuc:AdminValidator ID="AdminValidator6" runat="server" />
            </asp:RequiredFieldValidator>
            <label>
                Item Number</label>
            <asp:TextBox ID="tbxItemNumber" runat="server" CssClass="text" Width="72px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="tbxItemNumber"
                ErrorMessage="Please provide item number" Display="dynamic" SetFocusOnError="true">
                <wuc:AdminValidator ID="AdminValidator7" runat="server" />
            </asp:RequiredFieldValidator>
             <br />
            <label>
                MSRP $</label>
            <asp:TextBox ID="tbxRetailPrice" runat="server" CssClass="text" Width="52px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbxRetailPrice"
                ErrorMessage="Please provide MSRP" Display="dynamic" SetFocusOnError="true">
                <wuc:AdminValidator ID="AdminValidator9" runat="server" />
            </asp:RequiredFieldValidator>
            <br />
            <label>
                Current Cost $</label>
            <asp:TextBox ID="tbxCurrentCost" runat="server" CssClass="text" Text="0" Width="52px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="tbxCurrentCost"
                ErrorMessage="Please Current Cost" Display="dynamic" SetFocusOnError="true">
                <wuc:AdminValidator ID="AdminValidator11" runat="server" />
            </asp:RequiredFieldValidator>
            <label>
                Sale Price $</label><asp:TextBox ID="tbxStandardCost" runat="server" CssClass="text"
                    Text="0" Width="52px"></asp:TextBox>
            <br />
            <label>
                Additional Price $</label><asp:TextBox ID="tbxAdditionalPrice" runat="server" CssClass="text"
                    Text="0" Width="52px"></asp:TextBox>
            <br />
            <label>
                Technical specs</label><br />
            <textarea name="ckeTechicalSpecs" id="ckeTechicalSpecs"></textarea>
            <input id="hidTechnicalSpec" type="hidden" runat="server" />
            <br />
            <label>
                Upload Image</label>
            <asp:Image ID="imgProductDefaultImagePreview" runat="server" Visible="false" />
            <asp:FileUpload ID="fluProductDefaultImage" runat="server" />
            <br />
            <label>
                Stock Amount
            </label>
            <asp:TextBox ID="tbxStock" runat="server" CssClass="text" Width="50px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="tbxStock"
                ErrorMessage="Stock amount is required" Display="dynamic" SetFocusOnError="true">
                <wuc:AdminValidator ID="AdminValidator10" runat="server" />
            </asp:RequiredFieldValidator>
            <br />
            <label>
                Package Quanity
            </label>
            <asp:TextBox ID="tbxPkgQuanity" runat="server" CssClass="text" Text="0" Width="50px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="tbxPkgQuanity"
                ErrorMessage="Package Quanity is required" Display="dynamic" SetFocusOnError="true">
                <wuc:AdminValidator ID="AdminValidator13" runat="server" />
            </asp:RequiredFieldValidator>
            <br />
            
            <label>
                Upload Additional Image</label>
            <div id="fileUploadContainer">
                <div id="divAdditionalPreviews" visible="false" runat="server">
                    <asp:Repeater ID="rptAdditionalPreview" runat="server">
                        <ItemTemplate>
                            <asp:Image ID="imgPreview" runat="server" ImageUrl='<%# Container.DataItem %>' />
                        </ItemTemplate>
                    </asp:Repeater>
                </div>
                <input type="file" id="fuImageAdditional" name="fuImageAdditional[]" />
                <a href="javascript:void(0);" onclick="CreateNewFileUploader();">Add More</a>
            </div>
            <br />
            <label>
                Weight</label>
            <asp:TextBox ID="tbxWeight" runat="server" CssClass="text" Width="50px"></asp:TextBox>
            <span>lbs</span>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="tbxWeight"
                Display="dynamic" ErrorMessage="<%$ Code:ECommerce.Library.RegExUtil.DecimalFormatError %>"
                ValidationExpression="<%$ Code:ECommerce.Library.RegExUtil.DecimalFormat %>">
                <wuc:AdminValidator ID="AdminValidator2" runat="server" />
            </asp:RegularExpressionValidator>
            <asp:TextBox ID="tbxWeightUnit" runat="server" CssClass="text" Width="50px"></asp:TextBox>
            <span>oz.</span>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="tbxWeightUnit"
                Display="dynamic" ErrorMessage="<%$ Code:ECommerce.Library.RegExUtil.DecimalFormatError %>"
                ValidationExpression="<%$ Code:ECommerce.Library.RegExUtil.DecimalFormat %>">
                <wuc:AdminValidator ID="AdminValidator4" runat="server" />
            </asp:RegularExpressionValidator>
            <br />
            <label>
                Size</label>
            <asp:TextBox ID="tbxSize" runat="server" Width="50px" CssClass="text"></asp:TextBox>
            <br />
            <label>
                Active</label>
            <asp:CheckBox ID="cbxIsActive" runat="server" />
        </fieldset>
        <fieldset>
            <asp:Panel ID="ExtraFields" runat="server" Visible="false">
                <label>
                    Length</label>
                <asp:TextBox ID="tbxLengthWholeFirstDigit" runat="server" CssClass="text" MaxLength="1"
                    Width="20px"></asp:TextBox>
                <asp:TextBox ID="tbxLengthWholeSecondDigit" runat="server" CssClass="text" MaxLength="1"
                    Width="20px"></asp:TextBox>
                <asp:TextBox ID="tbxLengthFractionFirstDigit" runat="server" CssClass="text" MaxLength="3"
                    Width="22px"></asp:TextBox>
                /
                <asp:TextBox ID="tbxLengthFractionSecondDigit" runat="server" CssClass="text" MaxLength="3"
                    Width="22px"></asp:TextBox>
                <br />
                <label>
                    Width</label>
                <asp:TextBox ID="tbxWidthWholeFirstDigit" runat="server" CssClass="text" MaxLength="1"
                    Width="20px"></asp:TextBox>
                <asp:TextBox ID="tbxWidthWholeSecondDigit" runat="server" CssClass="text" MaxLength="1"
                    Width="20px"></asp:TextBox>
                <asp:TextBox ID="tbxWidthFractionFirstDigit" runat="server" CssClass="text" MaxLength="3"
                    Width="22px">
                </asp:TextBox>
                /
                <asp:TextBox ID="tbxWidthFractionSecondDigit" runat="server" CssClass="text" MaxLength="3"
                    Width="22px"></asp:TextBox>
                <br />
                <label>
                    Diameter</label>
                <asp:TextBox ID="tbxDiameterWholeFirstDigit" runat="server" CssClass="text" MaxLength="1"
                    Width="20px"></asp:TextBox>
                <asp:TextBox ID="tbxDiameterWholeSecondDigit" runat="server" CssClass="text" MaxLength="1"
                    Width="20px"></asp:TextBox>
                <asp:TextBox ID="tbxDiameterFractionFirstDigit" runat="server" CssClass="text" MaxLength="3"
                    Width="22px"></asp:TextBox>
                /
                <asp:TextBox ID="tbxDiameterFractionSecondDigit" runat="server" CssClass="text" MaxLength="3"
                    Width="22px"></asp:TextBox>
                <br />
                <label>
                    Thread Count</label>
                <asp:TextBox ID="tbxThreadCountWholeFirstDigit" runat="server" CssClass="text" MaxLength="1"
                    Width="20px"></asp:TextBox>
                <asp:TextBox ID="tbxThreadCountWholeSecondDigit" runat="server" CssClass="text" MaxLength="1"
                    Width="20px"></asp:TextBox>
                <asp:TextBox ID="tbxThreadCountFractionFirstDigit" runat="server" CssClass="text"
                    MaxLength="3" Width="22px"></asp:TextBox>
                /
                <asp:TextBox ID="tbxThreadCountFractionSecondDigit" runat="server" CssClass="text"
                    MaxLength="3" Width="22px"></asp:TextBox>
            </asp:Panel>
            <br />
            <label>
                At a Glance</label>
            <textarea name="editor1" id="ckeditor"></textarea>
            <input id="hidDescription" type="hidden" runat="server" />
            <br />
            <label>
                Full Features</label>
            <textarea name="editor1" id="RecipiesEditor"></textarea>
            <input id="hidRecipies" type="hidden" runat="server" />
            <br />
            <label>
               In the Box</label>
            <textarea name="editor1" id="AddiEditor"></textarea>
            <input id="hidAdditionalInfo" type="hidden" runat="server" />
            <label>
                Featured Listing</label>
            <asp:CheckBox ID="cbxFeatured" runat="server" />
            <label>
                Special</label>
            <asp:CheckBox ID="cbxSpecial" runat="server" />
            <br />
            <label>Partner(s) and Price(s)</label>
            <br />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">
                <ContentTemplate>
                    <table class="GridView">
                        <tr class="HeaderStyle">
                            <td>
                                Brand
                            </td>
                            <td>
                                Production Cost($)
                            </td>
                            <td>
                                Sell price($)
                            </td>
                        </tr>
                        <asp:Repeater ID="repProductPartners" runat="server" OnItemDataBound="repProductPartners_ItemDataBound">
                            <ItemTemplate>
                                <tr class="RowStyle">
                                    <td>
                                        <asp:DropDownList ID="ddlBrandName" runat="server" class="partners">
                                        </asp:DropDownList>
                                         <asp:RequiredFieldValidator ID="rfvddlBrandName" ControlToValidate="ddlBrandName" SetFocusOnError="true" Display="Dynamic" InitialValue="-1" ValidationGroup="valGrpPartnerSelection" runat="server" ErrorMessage="*"></asp:RequiredFieldValidator>
                                        <input id="hidProdPartnerId" type="hidden" value='<%# Eval("PartnerProductId")%>'
                                            runat="server" />
                                    </td>
                                    <td align="right">
                                        <asp:TextBox ID="txtProductionCost" runat="server" Text='<%# Eval("ProductionCost")%>'
                                            Width="80px"></asp:TextBox>
                                            <asp:RegularExpressionValidator ID="revtxtProductionCost" runat="server" ControlToValidate="txtProductionCost" ErrorMessage="*" ToolTip="format should be ##.##"  SetFocusOnError="true" ValidationExpression="^[0-9]+.[0-9]{2}$"></asp:RegularExpressionValidator>
                                    </td>
                                    <td align="right">
                                        <asp:TextBox ID="txtSellPrice" runat="server" Text=' <%# Eval("SellPrice")%>' Width="80px"></asp:TextBox>
                                        <asp:RegularExpressionValidator ID="rfvtxtSellPrice" runat="server" ControlToValidate="txtSellPrice" ErrorMessage="*" ToolTip="format should be ##.##"  SetFocusOnError="true" ValidationExpression="^[0-9]+.[0-9]{2}$"></asp:RegularExpressionValidator>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                        <tr>
                            <td colspan="3" align="right">
                                <asp:LinkButton ID="lnbAddNew" runat="server" OnClick="lnbAddNew_Click" CausesValidation="false">Add New</asp:LinkButton>
                            </td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:UpdatePanel>
        </fieldset>
        <div class="btn-place-holder">
            <asp:Button ID="imgSaveBottom" runat="server" OnClick="Create_Click" CssClass="button medium black"
                Text="Save Product" OnClientClick="javascript:return GetCKEditorData();" />
        </div>
        <br class="clear" />
    </div>
    <br class="clear" />
    <script type="text/javascript">
        function CreateNewFileUploader() {
            var newUploader = '<div class="divAdditional">' +
                              '<div>' +
                              '</div>' +
                              '<div style="height: 5px;">' +
                              '&nbsp;</div>' +
                              '<div>' +
                              '<input type="file" id="fuImageAdditional" name="fuImageAdditional[]" />' +
                              '<a href="javascript:void(0);" onclick="CreateNewFileUploader();">Add More</a>' +
                              '&nbsp;<a href="javascript:void(0);" onclick="RemoveFileUploader(this);">Remove</a>' +
                              '</div>' +
                              '</div>';
            $("#fileUploadContainer").append(newUploader);
        }

        function RemoveFileUploader(elem) {
            var $divContainer = $(elem).parent().parent();
            $divContainer.remove();
        }

        $(document).ready(function () {
            $('#ckeditor').ckeditor({ toolbar: "Basic" });
            $('#RecipiesEditor').ckeditor({ toolbar: "Basic" });
            $('#AddiEditor').ckeditor({ toolbar: "Basic" });
            $('#ckeTechicalSpecs').ckeditor({ toolbar: "Basic" });

            $('#ckeditor').val($("#<%= hidDescription.ClientID %>").val());
            $('#RecipiesEditor').val($("#<%= hidRecipies.ClientID %>").val());
            $('#AddiEditor').val($("#<%= hidAdditionalInfo.ClientID %>").val());
            $('#ckeTechicalSpecs').val($("#<%= hidTechnicalSpec.ClientID %>").val());


            $(".partners").change(function () {

                var totalCount = 0;
                var cur_val = $(this).val();
                var cur_id = $(this).attr("id");

                $('.partners option:selected').each(function () {
                    if ($(this).val() == cur_val) {
                        totalCount = totalCount + 1;
                    }
                });

                if (totalCount >= 2) {
                    $("#" + cur_id).val(-1);
                    totalCount = 0;
                    alert("Cant select a partner more then once");
                }



            });

        });
        function GetCKEditorData() {
            var description = $('#ckeditor').val();
            var recep = $('#RecipiesEditor').val();
            var addition = $('#AddiEditor').val();
            if (description != "") {
                $("#<%= hidDescription.ClientID %>").val(description);
            }
            if (recep != "") {
                $("#<%= hidRecipies.ClientID %>").val(recep);
            }
            if (addition != "") {
                $("#<%= hidAdditionalInfo.ClientID %>").val(addition);
            }
        }
        function ResetFields() {
            $('#ckeditor').val() = '';
            $('#RecipiesEditor').val() = '';
            $('#AddiEditor').val() = '';
            $("#ckeTechicalSpecs").val('');
        }

    </script>
</asp:Content>
